package drone;

/**
 * 
 * @author Robert Verginien Nickel
 */
import java.util.ArrayList;

public class Space implements Comparable<Space>{
	
	private boolean isEmpty = true;
	private Coordinates coordinates;
	private ArrayList<Coordinates> wayPoints;
        private int id;
	double distanceToStart;
	
	/**
	 * @param coordinates 
	 * @param wayPoints
	 * @param distanceToStart needed for sorting
	 */
	public Space(Coordinates coordinates, ArrayList<Coordinates> wayPoints, int id){
		this.coordinates = coordinates;
		this.wayPoints = wayPoints;
                this.id = id;
                wayPoints.add(coordinates);
                this.distanceToStart = calculateDistance();
	}

	public double getDistanceToStart() {
		return distanceToStart;
	}

	public void setDistanceToStart(double distanceToStart) {
		this.distanceToStart = distanceToStart;
	}

	public boolean isEmpty() {
		return isEmpty;
	}

	public void setEmpty(boolean isEmpty) {
		this.isEmpty = isEmpty;
	}

	public Coordinates getCoordinates() {
		return coordinates;
	}

	public void setCoordinates(Coordinates coordinates) {
		this.coordinates = coordinates;
	}

	public ArrayList<Coordinates> getWayPoints() {
		return wayPoints;
	}

	public void setWayPoints(ArrayList<Coordinates> wayPoints) {
		this.wayPoints = wayPoints;
	}

        /**
         * for changing the pedestrian gate (exit from the parking lot), change here!
         * @return the distance of a space to the pedestrian gate (in our programm visualized with a palm)
         */
        private double calculateDistance() {
            double distance = getVectorLength(new Coordinates(1,1), wayPoints.get(wayPoints.size()-1));
            return distance;
        }
        /**
         *
         * @param coordsA The first..
         * @param coordsB ..and second Coordinate, to get the distance between
         * @return the euclidean distance between the two Coordinates
         */
        private double getVectorLength(Coordinates coordsA, Coordinates coordsB){
            double length;
            double a = Math.abs(coordsA.getxPos()-coordsB.getxPos());
            double b = Math.abs(coordsA.getzPos()-coordsB.getzPos());
            length = Math.sqrt(Math.pow(a, 2)+Math.pow(b, 2));
            return length;
        }
        /**
         * this is used to make it possible to sort the spaces
         * with Collection.sort() depending on the distance to the start
         * @param space
         * @return 
         */
	@Override
	public int compareTo(Space space) {
            return ((Double) getDistanceToStart()).compareTo((Double) space.distanceToStart);
	}
}
